# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=hdmi-sniff
pkgver=5.f7fbc0e
pkgrel=5
groups=('blackarch' 'blackarch-hardware' 'blackarch-sniffer' 'blackarch-cracker')
pkgdesc='HDMI DDC (I2C) inspection tool. It is designed to demonstrate just how easy it is to recover HDCP crypto keys from HDMI devices.'
arch=('any')
url='https://github.com/ApertureLabsLtd/hdmi-sniff'
license=('custom:unknown')
depends=('python2' 'python2-pyserial' 'hdcp-genkey')
makedepends=('git')
source=("git+https://github.com/ApertureLabsLtd/$pkgname.git")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  echo $(git rev-list --count HEAD).$(git rev-parse --short HEAD)
}

prepare() {
  cd $pkgname

  sed -i 's|/usr/bin/env python|/usr/bin/env python2|' hdmi-sniff.py
  sed -i 's|/usr/bin/env python|/usr/bin/env python2|' hdmi_ddc.py
  sed -i 's|/hdcp-master.txt|/usr/share/hdmi-sniff/hdcp-master.txt|' hdmi_ddc.py
  sed -i 's|/master-key.txt|/usr/share/hdmi-sniff/master-key.txt|' hdmi_ddc.py

  git clone https://github.com/rjw57/hdcp-genkey
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/bin"

  install -Dm 755 "$pkgname.py" "$pkgdir/usr/share/$pkgname/hdmi-sniff.py"
  install -m 644 hdmi_ddc.py "$pkgdir/usr/share/$pkgname/hdmi_ddc.py"
  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" README.md
  cp -a hdcp-genkey/* "$pkgdir/usr/share/$pkgname/"

  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
cd /usr/share/$pkgname
exec python2 $pkgname.py "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname"
}

